<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    function ListNode(val, next) {
        this.val = (val===undefined ? 0 : val)
        this.next = (next===undefined ? null : next)
    }

    var l1 = new ListNode(1);
    l1.next = new ListNode(2);
    l1.next.next = new ListNode(4);

    var l2 = new ListNode(1);
    l2.next = new ListNode(3);
    l2.next.next = new ListNode(4);
    var mergeTwoLists = function(l1, l2) {
        var l3 = new ListNode(0);
        var res = l3;
        debugger;
        while(l1 || l2){
            if(l1 && l2){
                var val1 = l1. val
                var val2 = l2. val

                if(val1<=val2){
                    l3.next=l1
                    l3 = l3.next;
                    l3.next = l2;
                }else {
                    l3.next=l2
                    l3 = l3.next;
                    l3.next = l1;
                }
                
                l1 = l1.next;
                l2 = l2.next;
            }else {
                if(l2){
                    l3.next = l2
                }else {
                    l3.next = l1
                }
            }        
        }
        debugger
        return res.next
    };
    mergeTwoLists(l1,l2)
    </script>
</body>
</html>